import { message,applicationstatus } from "../../server/api";
Page({
  /**
   * 页面的初始数据
   */
  data: {
    avt:
      "https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0",
    list: [
      {
        img: "/new_icon/组 12@3x.png",
        title: "积分中心",
      },
      {
        img: "/new_icon/组 13@3x.png",
        title: "公益活动",
      },
      {
        img: "/new_icon/组 14@3x.png",
        title: "活动上报",
      },
      {
        img: "/new_icon/组 15@3x.png",
        title: "积分商城",
      },
    ],
    data: [
      {
        icon: "/icon/我的-归属地管理x64.png",
        name: "归属地管理",
      },
      {
        icon: "/icon/我的-积分记录x64.png",
        name: "积分记录",
      },
      {
        icon: "/icon/我的-积分规则x64.png",
        name: "积分规则",
      },
      {
        icon: "/icon/我的-成为商家x64.png",
        name: "成为商家",
      },
      {
        icon: "/icon/我的-关于我们x64.png",
        name: "关于我们",
      },
    ],
    phone: "",
    djimg: "", //等级icon
    honorimg: "", //荣誉icon
    dj:"",
    honor:"",
    map: {},
    status:'3'
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {},

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {},

  /**
   * 生命周期函数--监听页面显示
   */
  async onShow() {
    this.getTabBar().toggleMenu(0)
    this.getTabBar().init();
    this.getmessage();
    this.setData({ phone: this.maskPhoneNumber(wx.getStorageSync("phone")) });
    const userid = wx.getStorageSync("id");
    const res = await applicationstatus(userid)
    if(res.code == 200)
    {
      this.setData({status:res.result == null ? "3" : res.result})
    }
  },
  //获取用户信息
  async getmessage() {
    const that = this;
    const userid = wx.getStorageSync("id");
    const data = await message(userid);
    if (data.code == 200) {
      const obj = data.result;
      console.log(obj,'obj');
      this.setData({honor:obj.maxhonor})
      switch (obj.maxgrade) {
        case 1:
          that.setData({ djimg: "../../icon/等级图标/普通x280.png" ,dj:'普通'});
          break;
        case 2:
          that.setData({ djimg: "../../icon/等级图标/青铜x280.png",dj:'青铜' });
          break;
        case 3:
          that.setData({ djimg: "../../icon/等级图标/白银x280.png",dj:'白银'});
          break;
        case 4:
          that.setData({ djimg: "../../icon/等级图标/黄金x280.png",dj:'黄金' });
          break;
        case 5:
          that.setData({ djimg: "../../icon/等级图标/铂金x280.png",dj:'铂金' });
          break;
        case 6:
          that.setData({ djimg: "../../icon/等级图标/钻石x280.png",dj:'钻石' });
          break;
        default:
          break;
      }
      switch (obj.maxhonor) {
        case 1:
          that.setData({honorimg:'../../icon/勋章图标/勋章1x280.png'})
          break;
          case 2:
            that.setData({honorimg:'../../icon/勋章图标/勋章2x280.png'})
          break;
          case 3:
            that.setData({honorimg:'../../icon/勋章图标/勋章3x280.png'})
           break;
           case 4:
            that.setData({honorimg:'../../icon/勋章图标/勋章4x280.png'})
           break;
           case 5:
            that.setData({honorimg:'../../icon/勋章图标/勋章5x280.png'})
           break;
           case 6:
            that.setData({honorimg:'../../icon/勋章图标/勋章6x280.png'})
           break;
           case 7:
            that.setData({honorimg:'../../icon/勋章图标/勋章7x280.png'})
           break;
           case 8:
            that.setData({honorimg:'../../icon/勋章图标/勋章8x280.png'})
           break;
           case 9:
            that.setData({honorimg:'../../icon/勋章图标/勋章9x280.png'})
           break;
           case 10:
            that.setData({honorimg:'../../icon/勋章图标/勋章10x280.png'})
           break;
        default:
          break;
      }
    }
  },
  //常用功能跳转页面
  detail(e) {
    const { index } = e.currentTarget.dataset;
    switch (index) {
      case 0:
        wx.setStorageSync('active', '0')
        wx.switchTab({
          url: `/pages/pointcenter/pointcenter`,
        });
        wx.setStorageSync('count', 4)
        break;
      case 1:
        wx.navigateTo({
          url: "/subPackagesA/pages/werlfarr/werlfarr",
        });
        break;
      case 2:
        wx.navigateTo({
          url: "/subPackagesA/pages/report/report",
        });
        break;
      case 3:
        wx.switchTab({
          url: "/pages/home/home",
        });
        break;
      default:
        break;
    }
  },
  //关于我们跳转页面
  pages(e) {
    const { index } = e.currentTarget.dataset;
    switch (index) {
      case 0:
        wx.navigateTo({
          url: "/subPackagesA/pages/belonging/belonging",
        });
        break;
      case 1:
        wx.setStorageSync('active', '0')
        wx.setStorageSync('count', 4)
        wx.switchTab({
          url: "/pages/pointcenter/pointcenter",
        });
        break;
      case 2:
        wx.navigateTo({
          url: "/subPackagesA/pages/pointsrule/pointsrule",
        });
        break;
      case 3:
          if(this.data.status == 3)
          {
            wx.navigateTo({
              url: "/subPackagesA/pages/merchant/merchant",
            });
          }else if(this.data.status == 2){
            wx.switchTab({
              url: '/pages/merchanthome/merchanthome',
            })
          }else{
            wx.navigateTo({
              url: `/subPackagesA/pages/audit/audit?status=${this.data.status}`,
            });
          }
        break;
      default:
        wx.navigateTo({
          url: "/subPackagesA/pages/aboutus/aboutus",
        });
        break;
    }
  },
  //荣誉
  hoor() {
    wx.navigateTo({
      url: "/subPackagesA/pages/honor/honor",
    });
  },
  grade() {
    wx.navigateTo({
      url: "/subPackagesA/pages/grade/grade",
    });
  },
  //将手机号中间四位替换掉
  maskPhoneNumber(phoneNumber) {
    return phoneNumber.replace(/(\d{3})\d{4}(\d{4})/, "$1****$2");
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {},

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {},

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {},
});
